package com.lanswon.carlocationsearch.service;

import cn.hutool.json.JSONObject;
import com.lanswon.carlocationsearch.dao.CPicrecordMapper;
import com.lanswon.carlocationsearch.dto.CPicrecordDto;
import com.lanswon.carlocationsearch.dto.ImportDataDto;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description
 * @Author zsw
 * @Date 2019/12/5 20:39
 * @Version V1.0
 **/

@Service
public class CarService {

    @Autowired
    private CPicrecordMapper cPicrecordMapper;

    public List<JSONObject> queryCPicrecordsByCard1(List<ImportDataDto> importData, int count) {


        List<JSONObject> ljo = new ArrayList<>();

        for(ImportDataDto importDataDto:importData) { //2

            String dateTime = DateFormatUtils.format(importDataDto.getDateTime(), "YYYY/MM/dd HH:mm:ss");

            List<CPicrecordDto> list = cPicrecordMapper.queryCPicrecordsByCard1(importDataDto.getCarNum(),dateTime,count);
            JSONObject js = new JSONObject();
            js.put("carNum",importDataDto.getCarNum());
            js.put("dateTime", dateTime);
            js.put("illegalPlace",importDataDto.getIllegalPlace());

            for (int i=0;i<list.size();i++) { //3
                CPicrecordDto cPicrecordDto = list.get(i);
                js.put("passCarPlace"+i,cPicrecordDto.getDevName());
                js.put("passCarDate"+i,cPicrecordDto.getCapDate());

            }


            ljo.add(js);

        }




        return ljo;
    }

/*

    public List<JSONObject> queryCPicrecordsByCard(List<ImportDataDto> importData, int count) {

        List<CarDto> ll = new ArrayList<>();
        List<JSONObject> ljo = new ArrayList<>();
        String condition = CommonUtil.ListConventString(importData, count);

        List<CPicrecordDto> list = cPicrecordMapper.queryCPicrecordsByCard(condition);

        for(ImportDataDto importDataDto:importData) { //2
            for(CPicrecordDto cPicrecordDto:list) { //6
                if(importDataDto.getCarNum().equals(cPicrecordDto.setCarNum()) && ){

                }

            }
        }



        for(ImportDataDto importDataDto:importData){ //2
            JSONObject js = new JSONObject();
            js.put("carNum",importDataDto.getCarNum());
            js.put("dateTime", DateFormatUtils.format(importDataDto.getDateTime(),"YYYY/MM/dd HH:mm:ss"));
            js.put("illegalPlace",importDataDto.getIllegalPlace());

//            CPicrecordDto cPicrecordDto = list.get(i);




            for (int i=0;i<count;i++) { //3

                js.put("passCarPlace"+i,list.get((i+1).getDevName());
                js.put("passCarDate"+i,cPicrecordDto.getCapDate());

            }




                for(CPicrecordDto cPicrecordDto:list){ //6
                    for (int i=0;i<count;i++) { //3

                    if (importDataDto.getCarNum().equals(cPicrecordDto.getCarNum())) {

                        js.put("passCarPlace"+i,list.get((i+1).getDevName());
                        js.put("passCarDate"+i,cPicrecordDto.getCapDate());
                    }
                }


            }
            ljo.add(js);
        }






        return ljo;
    }

    */
}